package com.mk.common.quartz;

import java.util.concurrent.TimeUnit;

import org.junit.Test;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.ScheduleBuilder;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SimpleScheduleBuilder;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.quartz.impl.StdSchedulerFactory;

public class QuartzDemo {
	@Test
	public void test1() throws SchedulerException, InterruptedException {
		// 1、调度器
		Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
		// 2、任务实例
		JobDetail job = JobBuilder.newJob(QuartzTask.class).withIdentity("fundCreate", "mzjz").build();
		// 3、触发器
		// SimpleScheduleBuilder scheduleBuilder =
		// SimpleScheduleBuilder.simpleSchedule();
		// scheduleBuilder.repeatSecondlyForever(3);
		Trigger trigger = TriggerBuilder.newTrigger().withIdentity("trigger", "rescue").startNow()
				.withSchedule(SimpleScheduleBuilder.repeatSecondlyForever(3)).build();

		// 执行
		scheduler.scheduleJob(job, trigger);
		scheduler.start();
		// 终止
		TimeUnit.SECONDS.sleep(10);
		scheduler.shutdown();
	}
}
